#ifndef DECODERNC_H
#define DECODERNC_H

#include <newcode/ByteMatrix.h>
#include <newcode/encoder/EncoderGC.h>
#include <zxing/common/DecoderResult.h>

namespace newcode{
namespace decoder {

using namespace zxing;

class Decoder
{
private:
    int formatSize;
    bool formatIsString;
    int dimension;
    encoder::EncodeMode formatMode;
    Ref<ByteMatrix> theBytes;
    const static unsigned char MASK = 0xA8;
    const static float ERROR_CORECTION_LEVELS[];

    unsigned select2EqualFrom3(unsigned p1, unsigned p2, unsigned p3);
    ArrayRef<unsigned char> correctErrors(ArrayRef<unsigned char> codewordBytes,
        int numDataCodewords);

protected:
    ArrayRef<unsigned char> filterElement(ArrayRef<unsigned char> fromImage,
        encoder::EncodeMode mode);
    virtual void decodeFormatElements();
    virtual ArrayRef<unsigned char> decodeBytes();
    void getElementsFromImage(ArrayRef<unsigned char> elementsFromImage,
        int x, int y, bool isOdd = true);
    unsigned char selectFormatByte(int x, int y);
    int sizeWithECB(int size);

public:
     Ref<DecoderResult> decode(Ref<ByteMatrix> bytes);
};

}
}


#endif // DECODERNC_H
